{extend name="../../common/view/admin_base"/}

{block name="main"}
<div class="layui-fluid layui-form">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-table" id="tree-table" lay-size="sm"></table>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <button class="layui-btn" lay-submit lay-filter="layui-submit" id="layui-submit">提交</button>
    </div>
</div>

<script>
    layui.config({
        base: '__static__/layui/extend/'
    }).extend({
        treeGrid:'treeTable'
    }).use(['treeTable','layer','code','form','element','laytpl'],function(){
            var form = layui.form,
                layer = layui.layer,
                treeTable = layui.treeTable,
                tree = null;
            var laytpl = layui.laytpl;

            $.post("{:url('admin/group/setauth')}?type=getauthlist&id={$id}",function(res){
                tree = treeTable.render({
                    elem: '#tree-table',
                    data: res.data,
                    icon_key: 'title',
                    primary_key: 'id',
                    parent_key: 'pid',
                    is_checkbox: true,
                    is_cache: false,
                    checked: {
                        key: 'id',
                        data: res.authed,
                    },
                    end: function(e){
                        $("#tree-table .layui-icon-triangle-r").removeClass('layui-icon-triangle-r').addClass('layui-icon-triangle-d');
                        $("#tree-table tr.layui-hide").removeClass('layui-hide');
                        form.render();
                    },
                    cols: [
                        {
                            key: 'title', title: '名称',width: '160px',
                            template:function(item){
                                return '<a style="cursor:pointer;">'+item.title+'</a>';
                            }
                        },
                        {
                            key: 'action', title: '路径',width: '260px'
                        }
                    ]
                });
            });
        })
</script>
{/block}